
		$(function(){

			// Tabs
			$('#tabs').tabs();
			
			//hover states on the static widgets
			$('#dialog_link, ul#icons li').hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); }
			);
			
			// ajax the module select list
			$("#module_list").load("php/get_module_list.php", listcallback);
			function listcallback() {}
			
			// ajax the menu
			$("#menu").load("php/get_menu.php", menucallback);

			function menucallback() {
				$('#menu').treeview({
					animated:"fast",
					collapsed: true,
					unique: true,
					persist: "cookie",
					toggle: treeCallback
				});
				
				// remove? - persist: "cookie",
				
				function treeCallback(){}
				
				// ajax content when a blog is selected from the menu
				$("#menuitem a").click(function(event){
					
					$("#content").load("php/get_content.php", {id: ($(this).attr('id'))}, contentcallback);
				
					$("#content").show();		
				
					function contentcallback() {
						$("#accordion").accordion({ 
							header: "h3", 
							collapsible: true, 
							active: false
						});
						
						
					}
				
				});						
		
				// hide current content when another folder is clicked
				$("span.folder").click(function(event){
			
					$("#content").hide();
				});								
			
			};
			
			$("button.review").live("click", function(){
			
				var entry_id = $(this).attr('id');
				// alert(entry_id);
				var review = $(this).siblings('textarea').val();	
				var flagged = 0;
				if ($(this).siblings('input[name=flagged]').is(':checked')) {
					flagged = 1;
				}
				var reviewed = 0;
				if ($(this).siblings('input[name=reviewed]').is(':checked')) {
					reviewed = 1;
				}
				// ajax the review entry
				$(this).siblings("#review").load("php/insert_review.php", {
					entry_id: entry_id,
					review: review,
					flagged: flagged,
					reviewed: reviewed	
				},reviewcallback);
				
				function reviewcallback(){}
			
			});
			
			// connect up the module select list click with the menu item click
			// doesn't work on Safari?? - it does now
			$("#module_list").live("click", function(){
				var mid = $(this).val();
				$("span.folder").each(function() { 
					if ($(this).attr('value') == mid) {
						$(this).click();
					}
					return false;
				});	
			});
			
			// reverse of above
			$("span.folder").live("click", function(){
				var mid = $(this).attr('value');
				$("#module_list").val(mid);
			});
			
			$("#tag_cloud").load("php/get_cloud.php");
			
			$("#tag_count").load("php/get_word_count.php");
			
			// function contentcallback() {};
		
		});
